package leetcode.code0701;

import leetcode.IDebug;
import leetcode.helper.tree.TreeNode;

/**
 * 执行用时：0 ms, 在所有 Java 提交中击败了100.00%的用户
 *
 * 内存消耗：38.5 MB, 在所有 Java 提交中击败了97.97%的用户
 *
 * 通过测试用例：35 / 35
 */
public class Solution implements IDebug {

	public TreeNode insertIntoBST(TreeNode root, int val) {
		if (root == null) {
			return new TreeNode(val);
		}
		this.f(root, val);
		return root;
	}

	private void f(TreeNode root, int val) {
		if (val < root.val) {
			if (root.left == null) {
				root.left = new TreeNode(val);
			} else {
				this.f(root.left, val);
			}
		} else if (val > root.val) {
			if (root.right == null) {
				root.right = new TreeNode(val);
			} else {
				this.f(root.right, val);
			}
		}
	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
